﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Data.Common;
using System.Collections;
using Weibo.Entity;

namespace Weibo.Data
{
    public class Schools
    {
        public static long CreateSchool(School school)
        {
            return DatabaseProvider.GetInstance().CreateSchool(school);
        }
        public static string SaveClassPicPath(ClassSavePicPath picPathModel)
        {
            return DatabaseProvider.GetInstance().SaveClassPicPath(picPathModel);
        }

        public static IList<School> GetShoolsByLetLocType(int Location, string letter,int type)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetShoolsByLetLocType(Location, letter, type))
            {
                if (dt != null)
                {
                    IList<School> list = DbTranslate.Translate<School>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<TClassPhoto> GetClassPhotoList(long uid, long gid)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetClassPhotoList(uid, gid))
            {
                if (dt != null)
                {
                    IList<TClassPhoto> list = DbTranslate.Translate<TClassPhoto>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<SchoolClassPhotoDetails> GetClassPhotoDetailList(long classPhotoID, int page, int pageSize, ref int pageCount)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetClassPhotoDetailList(classPhotoID, page, pageSize, ref  pageCount))
            {
                if (dt != null)
                {
                    IList<SchoolClassPhotoDetails> list = DbTranslate.Translate<SchoolClassPhotoDetails>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<SchoolClassPhotoDetails> GetClassPhotoDetailListNoPage(long classPhotoID)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetClassPhotoDetailListNoPage(classPhotoID))
            {
                if (dt != null)
                {
                    IList<SchoolClassPhotoDetails> list = DbTranslate.Translate<SchoolClassPhotoDetails>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<SchoolCollege> GetShoolsCollegeByLetLocType(int uid)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetShoolsCollegeByLetLocType(uid))
            {
                if (dt != null)
                {
                    IList<SchoolCollege> list = DbTranslate.Translate<SchoolCollege>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<SchoolClass> GetShoolsClassByLetLocType(int schoolID ,int collegeID)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetShoolsClassByLetLocType(schoolID, collegeID))
            {
                if (dt != null)
                {
                    IList<SchoolClass> list = DbTranslate.Translate<SchoolClass>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static School GetSchoolByID(int id)
        {
            using (IDataReader dr = DatabaseProvider.GetInstance().GetSchoolByID(id))
            {
                if (dr != null)
                {
                    IList<School> list = DbTranslate.Translate<School>(dr);
                    dr.Close();
                    if (list != null && list.Count > 0)
                    {
                        return list[0];
                    }
                }
            }
            return null;
        }

        public static IList<School> GetSchoolsByLikeName(string name)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetSchoolsByLikeName(name))
            {
                if (dt != null)
                {
                    IList<School> list = DbTranslate.Translate<School>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<MiniBlog> SearchSchoolMiniBlog(int pageIndex, int pageSize, ref int rowCount, string key, int isOri, int location, DateTime? startTime, DateTime? endTime, int isMyself, int isMyFollow,
         long curUid, string someone, int isHavePic, int isHaveLink, int isHaveVideo, int isHaveMusic, int isHaveVote, string sort, long GroupID, int IsFriendShip)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().SearchSchoolMiniBlog(pageIndex, pageSize, ref rowCount, key, isOri, location, startTime, endTime, isMyself, isMyFollow, curUid, someone, isHavePic, isHaveLink, isHaveVideo, isHaveMusic, isHaveVote, sort, GroupID, IsFriendShip))
            {

                if (dt != null)
                {
                    IList<MiniBlog> list = DbTranslate.Translate<MiniBlog>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<MiniBlog> SearchSchoolMiniBlogForMbIndexAdvanced(int pageIndex, int pageSize, ref int rowCount, string key, int isOri, int isRet, DateTime? startTime, DateTime? endTime, int isMyself, int isMyFollow,
    long curUid, int isHavePic, int isHaveLink, int isHaveVideo, int isHaveMusic, int isHaveVote, string sort, long GroupID, int IsFriendShip)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().SearchSchoolMiniBlogForMbIndexAdvanced(pageIndex, pageSize, ref rowCount, key, isOri, isRet, startTime, endTime, isMyself, isMyFollow, curUid, isHavePic, isHaveLink, isHaveVideo, isHaveMusic, isHaveVote, sort, GroupID, IsFriendShip))
            {

                if (dt != null)
                {
                    IList<MiniBlog> list = DbTranslate.Translate<MiniBlog>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static IList<MiniBlog> GetTopSchool500MiniBlogsByQuery(string where, string sortField, string sortType)
        {
            using (DataTable dt = DatabaseProvider.GetInstance().GetTop500SchoolMiniBlogsByQuery(where, sortField, sortType))
            {
                if (dt != null)
                {
                    IList<MiniBlog> list = DbTranslate.Translate<MiniBlog>(dt);
                    if (list != null && list.Count > 0)
                    {
                        return list;
                    }
                }
            }
            return null;
        }
        public static string DelPhoto(long photoID)
        {
            return DatabaseProvider.GetInstance().DelPhoto(photoID); ;
        }
        public static string DelPhotoFolder(long classPhotoID)
        {
            return DatabaseProvider.GetInstance().DelPhotoFolder(classPhotoID); ;
        }
        public static SchoolClassPhotoDetails GetSinglePhotoDetail(long photoID)
        {
            using (IDataReader dr = DatabaseProvider.GetInstance().GetSinglePhotoDetail(photoID))
            {
                if (dr != null)
                {
                    IList<SchoolClassPhotoDetails> list = DbTranslate.Translate<SchoolClassPhotoDetails>(dr);
                    dr.Close();
                    if (list != null && list.Count > 0)
                    {
                        return list[0];
                    }
                }
            }
            return null;
        }

    }
}
